package com.zhongbei.controller;

import com.zhongbei.pojo.Participation;
import com.zhongbei.service.ParticipationService;
import com.zhongbei.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/participation")
public class ParticipationController {

    @Autowired
    private ParticipationService participationService;

    @PostMapping
    public Result<String> create(@RequestBody Participation participation) {
        int i = participationService.insertParticipation(participation);
        return i == 1 ? Result.success("新增成功") : Result.error("新增失败");
    }

    @PutMapping("/{recordId}")
    public Result<String> update(@PathVariable Integer recordId, @RequestBody Participation participation) {
        participation.setRecordId(recordId);
        int i = participationService.updateParticipation(participation);
        return i == 1 ? Result.success("修改成功") : Result.error("修改失败");
    }

    @DeleteMapping("/{participationId}")
    public Result<String> delete(@PathVariable Integer participationId) {
        int i = participationService.deleteParticipationByParticipationId(participationId);
        return i == 1 ? Result.success("删除成功") : Result.error("删除失败");
    }

    @GetMapping("/{participationId}")
    public Result<List<Participation>> getById(@PathVariable Integer participationId) {
        return Result.success(participationService.selectParticipationByParticipationId(participationId));
    }
}
